﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Wallpaper.Data.Migrations
{
    /// <inheritdoc />
    public partial class AddCarouselTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<byte>(
                name: "UploaderType",
                table: "wallpapers",
                type: "tinyint",
                nullable: false,
                defaultValue: (byte)0,
                comment: "上传人类型：0-用户，1-管理员",
                oldClrType: typeof(int),
                oldType: "byte",
                oldDefaultValue: 0,
                oldComment: "上传人类型：0-用户，1-管理员");

            migrationBuilder.AlterColumn<string>(
                name: "ThumbnailUrl",
                table: "wallpapers",
                type: "nvarchar(100)",
                maxLength: 100,
                nullable: true,
                comment: "缩略图URL（用于列表展示）",
                oldClrType: typeof(string),
                oldType: "nvarchar(100)",
                oldMaxLength: 100,
                oldComment: "缩略图URL（用于列表展示）");

            migrationBuilder.AlterColumn<byte>(
                name: "ReviewStatus",
                table: "wallpapers",
                type: "tinyint",
                nullable: false,
                defaultValue: (byte)0,
                comment: "审核状态：0-待审核，1-审核通过，2-审核不通过",
                oldClrType: typeof(bool),
                oldType: "byte",
                oldDefaultValue: false,
                oldComment: "审核状态：true-审核通过，false-待审核/未通过");

            migrationBuilder.AddColumn<string>(
                name: "category_url",
                table: "categories",
                type: "nvarchar(500)",
                maxLength: 500,
                nullable: false,
                defaultValue: "",
                comment: "分类图URL");

            migrationBuilder.AddColumn<bool>(
                name: "is_active",
                table: "categories",
                type: "bit",
                nullable: false,
                defaultValue: true,
                comment: "是否启用");

            migrationBuilder.CreateTable(
                name: "carousels",
                columns: table => new
                {
                    Id = table.Column<string>(type: "nvarchar(36)", maxLength: 36, nullable: false),
                    Title = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false, comment: "轮播图标题"),
                    carousel_url = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: false, comment: "轮播图URL"),
                    sort_order = table.Column<int>(type: "int", nullable: false, defaultValue: 0, comment: "排序序号"),
                    is_active = table.Column<bool>(type: "bit", nullable: false, defaultValue: true, comment: "是否启用"),
                    create_at = table.Column<DateTime>(type: "datetime2", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP", comment: "创建时间"),
                    update_at = table.Column<DateTime>(type: "datetime2", nullable: true, comment: "更新时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_carousels", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_carousels_active_sort",
                table: "carousels",
                columns: new[] { "is_active", "sort_order" });

            migrationBuilder.CreateIndex(
                name: "IX_carousels_create_at",
                table: "carousels",
                column: "create_at");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "carousels");

            migrationBuilder.DropColumn(
                name: "category_url",
                table: "categories");

            migrationBuilder.DropColumn(
                name: "is_active",
                table: "categories");

            migrationBuilder.AlterColumn<int>(
                name: "UploaderType",
                table: "wallpapers",
                type: "byte",
                nullable: false,
                defaultValue: 0,
                comment: "上传人类型：0-用户，1-管理员",
                oldClrType: typeof(byte),
                oldType: "tinyint",
                oldDefaultValue: (byte)0,
                oldComment: "上传人类型：0-用户，1-管理员");

            migrationBuilder.AlterColumn<string>(
                name: "ThumbnailUrl",
                table: "wallpapers",
                type: "nvarchar(100)",
                maxLength: 100,
                nullable: false,
                defaultValue: "",
                comment: "缩略图URL（用于列表展示）",
                oldClrType: typeof(string),
                oldType: "nvarchar(100)",
                oldMaxLength: 100,
                oldNullable: true,
                oldComment: "缩略图URL（用于列表展示）");

            migrationBuilder.AlterColumn<bool>(
                name: "ReviewStatus",
                table: "wallpapers",
                type: "byte",
                nullable: false,
                defaultValue: false,
                comment: "审核状态：true-审核通过，false-待审核/未通过",
                oldClrType: typeof(byte),
                oldType: "tinyint",
                oldDefaultValue: (byte)0,
                oldComment: "审核状态：0-待审核，1-审核通过，2-审核不通过");
        }
    }
}
